package com.yanqu.road.server.cmd.patrons;

import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.logic.pb.PatronsPb;
import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PATRONS_PROMOTE, desc = "门客晋升")
public class PatronsPromoteCmd extends AbstractCommand {

    int patronsId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PatronsProto.PatronsPromoteReqMsg reqMsg = PatronsProto.PatronsPromoteReqMsg.parseFrom(packet.getBytes());
        patronsId = reqMsg.getPatronsId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(PatronsModule.class).patronsPromote(patronsId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret > 0) {
            PatronsProto.PatronsPromoteRespMsg.Builder respMsg = PatronsProto.PatronsPromoteRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_PATRONS_PROMOTE, respMsg);
        }
    }
}
